class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        //定义窗口
        int left=0;
        int right=0;
        int sum=0;
        int len=0;
        //如果右指针大于数组的长度返回0
        while(right<nums.length){
            sum=sum+nums[right];//进窗口
            while(sum>=target){
                len = right + 1 - left;

                sum=sum-nums[left];//出窗口
                left++;
            }
            int oldlen=len;
            if(oldlen<len) {
                len=oldlen;
            }
            right++;

        }

        return len;


    }
}
public class demo7 {
    public static void main(String[] args) {
        Solution solution=new Solution();
        int[] nums={5,1,3,5,10,7,4,9,2,8};
        int a=solution.minSubArrayLen(15,nums);
        System.out.println(a);
    }
}
